# -*- coding:utf-8 -*-


def binary_search(data, target, low, high) -> (bool, int):
    """二分查找的适用范围：data有序

    :param data: 有序序列
    :param target: 查找的目标
    :param low:
    :param high:
    :return: bool=是否查找到target; int=如果查找到为target在data中的下标，如果没有查找到为-1
    """
    if low > high:
        return False, -1
    mid = (low + high) // 2
    if target == data[mid]:
        return True, mid
    elif target > data[mid]:
        return binary_search(data, target, mid + 1, high)
    else:
        return binary_search(data, target, low, mid - 1)
